package com.tjmc.tiomsresource.collect;

import com.tjmc.tiomsresource.service.OmcResDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Luc
 * @version 1.0
 * @date 2020-05-26 14:54
 * @decription 执行清洗脚本
 */

//清洗数据
@Service
@PropertySource({"classpath:nce.properties"})
public class OmcResDBDataCleanJob {

    private static Logger logger = LoggerFactory.getLogger(OmcResDBDataCleanJob.class);

    @Value("${omc.res.clean-script-base}")
    private String baseCleanPath;
    @Value("${omc.res.clean-script-busi-pre}")
    private String busiPreCleanPath;
    @Value("${omc.res.clean-script-busi-post}")
    private String busiPostCleanPath;

    @Autowired
    private OmcResDataService omcResDataService;

    public void CleanData() {
        logger.info("读取清洗脚本: " + baseCleanPath);
        List<String> sqls = omcResDataService.readSqlFile(baseCleanPath);
        logger.info("执行清洗脚本: " + baseCleanPath);
        omcResDataService.executeSqls(sqls);
        logger.info("执行清洗脚本完成: " + baseCleanPath);

        logger.info("读取脚本: " + busiPreCleanPath);
        sqls = omcResDataService.readSqlFile(busiPreCleanPath);
        logger.info("执行清洗脚本: " + busiPreCleanPath);
        omcResDataService.executeSqls(sqls);
        logger.info("执行清洗脚本完成: " + busiPreCleanPath);

        logger.info("执行清洗更新lbs开始");
        omcResDataService.updateTranPtnLbsInClean();
        logger.info("读取脚本更新lbs结束");

        logger.info("读取脚本: " + busiPostCleanPath);
        sqls = omcResDataService.readSqlFile(busiPostCleanPath);
        logger.info("执行清洗脚本: " + busiPostCleanPath);
        omcResDataService.executeSqls(sqls);
        logger.info("执行清洗脚本完成: " + busiPostCleanPath);
    }
}
